﻿package Views{
	import flash.display.Sprite;
	import Player.SnakeHead;
	import flash.geom.Point;
	import flash.display.CapsStyle;
	import flash.display.JointStyle;
	

	public class CollisionField extends Sprite{
		private var fieldWidth:Number;
		private var fieldHeight:Number;

		public function CollisionField(newWidth:Number, newHeight:Number) {
			fieldWidth = newWidth;
			fieldHeight = newHeight;
			this.cacheAsBitmap = true;
			this.mouseEnabled = false;
		}
		
		/**
		* Update the collision map after a snake moved
		*/
		public function updateSnake(snake:SnakeHead,oldPosition:Point){
			// Square head makes nice curves
			if(snake.roundHead){
				graphics.lineStyle(snake.thickness, snake.tailColor, Game.alpha,Game.pixelHinting,Game.scaleMode,Game.caps,Game.joints);			
			}
			// Square head makes square corners
			else{
				graphics.lineStyle(snake.thickness,snake.tailColor,Game.alpha,Game.pixelHinting,Game.scaleMode,CapsStyle.SQUARE,JointStyle.MITER);
			}
			graphics.moveTo(snake.position.x,snake.position.y);
			graphics.lineTo(oldPosition.x,oldPosition.y);
		}
		
		public function emptyField():void{
			graphics.clear();
			graphics.lineStyle(5,Field.BORDER_COLOR);
			graphics.drawRect(0,0,fieldWidth,fieldHeight);
		}

	}
	
}
